//
// Created by hjie on 23-6-22.
//

#pragma once

#include <memory>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <mutex>
#include "logic/message_router.h"

class ServerManager;
class ConnectionDataRoom;

class RoomManager
{
public:
    explicit RoomManager(ServerManager * server_manager);
    ~RoomManager();

    std::shared_ptr<ConnectionDataRoom> AddRoom(const std::string & room_id);
    void RemoveRoom(const std::string & room_id);
    void CheckIdleRoom();
    MessageRouter * GetMessageRouter() { return m_message_router; }
    void PushCheckIdleRoom(const std::shared_ptr<ConnectionDataRoom>& room);
private:
    std::mutex m_mtx;
    std::map<std::string, std::shared_ptr<ConnectionDataRoom>> m_room_map;
    std::set<std::string> m_check_idle_room_set;
private:
    MessageRouter * m_message_router;
    ServerManager * m_server_manager;
};
